/*
 * @Description: chineseUtil
 * @Author: zhaokun
 * @Date: 2022-01-11 08:59:19
 * @LastEditTime: 2022-01-11 14:13:47
 * @FilePath: \user\common\nwChinese.GO
 */
package common

import (
	"github.com/mozillazg/go-pinyin"
	"github.com/yanyiwu/gojieba"
)

var seg = gojieba.NewJieba()

type ChineseUtil interface {
	CutAll(str string) []string
	Cut(str string) []string
	CutForSearch(str string) []string
	Pinyin(str string) string
}

type nwChineseUtil struct {
}

func NewNwChineseUtil() *nwChineseUtil {
	return &nwChineseUtil{}
}

/**
* @escription: 全模式
* @param {string} str
* @return string
 */
func (chineseUtil *nwChineseUtil) CutAll(str string) []string {
	resWords := seg.CutAll(str)
	return resWords
}

/**
 * @description: 精确模式
 * @param {string} str
 * @return string
 */
func (chineseUtil *nwChineseUtil) Cut(str string) []string {
	resWords := seg.Cut(str, true)
	return resWords
}

/**
 * @description: 搜索引擎分词
 * @param {string} str
 * @return {*}
 */
func (chineseUtil *nwChineseUtil) CutForSearch(str string) []string {
	resWords := seg.CutForSearch(str, true)
	return resWords
}

/**
 * @description: 拼音
 * @param {string} str
 * @return string
 */
func (chineseUtil *nwChineseUtil) Pinyin(str string) []string {
	pinyinUtil := pinyin.NewArgs()
	return pinyin.LazyPinyin(str, pinyinUtil)
}
